/*
 * Copyright 2013-2015 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xdtech.coder.init;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xdtech.common.service.impl.BaseService;
import com.xdtech.common.utils.EmptyUtil;
import com.xdtech.core.init.SysInitOperation;
import com.xdtech.core.model.BaseModel;
import com.xdtech.sys.model.CodeValue;
import com.xdtech.sys.model.DictionaryCode;
import com.xdtech.sys.model.MenuFunction;
import com.xdtech.sys.model.Operation;
import com.xdtech.sys.model.Params;

/**
 * 
 * @author max.zheng
 * @create 2015-4-4下午4:37:15
 * @since 1.0
 * @see
 */
public class CoderInit implements SysInitOperation{
	Log log = LogFactory.getLog(CoderInit.class);
	/**
	 * @description
	 * @author max.zheng
	 * @create 2015-4-4下午4:37:31
	 * @modified by
	 * @param baseService
	 */
	@Override
	public void initingToDb(BaseService<BaseModel> baseService) {
		List params = (List) baseService.findByHql("from Params where code=? and codeValue=?", "CoderInit","true");
		log.info("敏捷开发模块数据库初始化......");
		if (EmptyUtil.isEmpty(params)) {
			MenuFunction m3 = new MenuFunction();
			m3.setIconName("icon-quick-coder");
			m3.setNameCN("敏捷开发");
			m3.setOperationCode("quick-coder");
			m3.setPageUrl(null);
//			m3.getRoles().add(superManager);
			baseService.save(m3);
			
			MenuFunction m31 = new MenuFunction();
			m31.setIconName("icon-coder-config");
			m31.setNameCN("代码速成");
			m31.setOperationCode("codecreater-manage");
			m31.setPageUrl("codeCreater.do?codeCreater");
//			m31.getRoles().add(superManager);
			m31.setParent(m3);
			baseService.save(m31);
			
			baseService.save(new Operation("新增属性","sys:coderFiled:add",m31));
			baseService.save(new Operation("删除属性","sys:coderFiled:delete",m31));
			
			//数据字典
			DictionaryCode dictionaryCode = new DictionaryCode("FIELD_TYPE","属性类型");
			baseService.save(dictionaryCode);
			baseService.save(new CodeValue("Integer","整型",1,dictionaryCode));
			baseService.save(new CodeValue("Long","长整型",2,dictionaryCode));
			baseService.save(new CodeValue("String","字符型",3,dictionaryCode));
			baseService.save(new CodeValue("Date","日期型",4,dictionaryCode));
			baseService.save(new CodeValue("Timestamp","时间型",5,dictionaryCode));
			baseService.save(new CodeValue("Double","浮点型",6,dictionaryCode));
			Params p = new Params("CoderInit", "true", "敏捷开发模块数据库初始化标记");
			baseService.save(p);
			log.info("敏捷开发模块数据库初始化......结束");
		}else {
			log.info("敏捷开发模块数据库已经初始化......完毕");
		}
		
		
		
	}

	/**
	 * @description
	 * @author max.zheng
	 * @create 2015-4-4下午4:37:31
	 * @modified by
	 * @param baseService
	 */
	@Override
	public void initingToCache(BaseService<BaseModel> baseService) {
		
	}

	/**
	 * @description
	 * @author max.zheng
	 * @create 2015-4-4下午4:37:31
	 * @modified by
	 * @return
	 */
	@Override
	public int getInitOrder() {
		return 5;
	}

	/* (非 Javadoc)
	 * initingToWebApplication
	 * <p>对override方法的补充说明，若不需要则删除此行</p>
	 * 
	 * @param baseService
	 * @see com.xdtech.core.init.SysInitOperation#initingToWebApplication(com.xdtech.common.service.impl.BaseService)
	 */
	@Override
	public void initingToWebApplication(BaseService<BaseModel> baseService)
	{
		// TODO Auto-generated method stub
		
	}

 }
